/*
This file is part of Docking@Home.
http://docking.gcl.cis.udel.edu
Copyright (C) 2009 University of Delaware

Docking@Home is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Docking@Home is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Docking@Home.  If not, see <http://www.gnu.org/licenses/>.
*/
/*
	Filename: Resources.h
	Description: Part of the Low Level Tab that displays information
		about the current resource in the right half of the tab
		window
	Revision History: 
		Created - 01/21/08
	Author: Robert Keller (01/21/08 -> Current)
*/

#ifndef _Resources_h
#define _Resources_h

#include "../GLHelper.h"
#include "../Math/MathHelper.h"

#include <algorithm>
#include<string>
using namespace std;

#include <vector>
using std::vector;

#define RESOURCES_MAX_LENGTH 32
#define RESOURCES_MAX_FILENAME 512

class Resources
{
public:
	
	// Constructor / Destructor

	Resources();
	Resources(float r, float h, float ls);
	~Resources();

	// Initialization Functions

	void init (float r, float h, float ls);

	// Member Modifiers

	void setCylinderRadius (float r);
	void setCylinderHeight (float h);

	void setLineSpacing (float ls);

	void setUserTitlePos (float x, float y, float z);
	void setGroupTitlePos (float x, float y, float z);
	void setCylinderPos (float x, float y, float z);
	void setPercentageTitlePos (float x, float y, float z);

	void setUserName (const char * uname);
	void setGroupName (const char * gname);

	void setTextColor (const float color[4]);
	void setCylinderFullColor (const float color[4]);
	void setCylinderEmptyColor (const float color[4]);

	// Update Data 
	void updateData ();

	// Window Size Adjusting Functions 
	
	void resize (float topLeftX, float topLeftY, 
		float rightX, float xFactor, float yFactor,
		bool bFullscreen = false);

	// Rendering Functions
	
	void draw (double fracDone, bool bFullscreen = false);
	void drawUserInfo ();
	void drawPercentage (double fracDone);
	void drawMinEnergy ();
	void drawRMSD ();

private:
	// Minimum Energy Graph Modifiers
	void FixMinEnerPoints();

	// Minimum Energy Graph Accessors
	Point2fT getMinEnerGraphPoint (unsigned int index);
	unsigned int getNumMinEnerGraphPoints ();

	// RMSD Graph Modifiers
	void FixRMSDPoints();

	// Minimum Energy Graph Accessors
	Point2fT getRMSDGraphPoint (unsigned int index);
	unsigned int getNumRMSDGraphPoints ();

	// Summary File Readers
	void PercentDone(const char *filename,string *keys,double *data,size_t size);
	void Summary(const char *filename);

	// Required Variables
	static GLHelper * glHelper;

	// Text Scale Variables
	float textXScale;
	float textYScale;
	float textZScale;

	float currTextXScale;
	float currTextYScale;
	float currTextZScale;

	float lineSpacing;

	// --------------------------------------------
	// User Information
	// --------------------------------------------

	char userName[RESOURCES_MAX_LENGTH];
	char groupName[RESOURCES_MAX_LENGTH];

	char * userTitle;
	char * groupTitle;

	// User String Position Variables
	float userTitlePos[3];

	// Group String Position Variables
	float groupTitlePos[3];

	// --------------------------------------------
	// Percentage Chart
	// --------------------------------------------

	//Percentage Complete
	double percentDone;

	// Cylinder Sizing Variables
	float cylinderRadius;
	float cylinderHeight;

	float currCylinderRadius;
	float currCylinderHeight;

	// Percentage String Position Variables
	float percentageTitlePos[3];

	// Cylinder Position Variables
	float cylinderPos[3];
	float cylinderRotAxis[3];

	int angle;

	// Color Variables
	float textColor[4];
	float cylinderFullColor[4];
	float cylinderEmptyColor[4];

	char * percentageTitle;

	// --------------------------------------------
	// Minimum Energy
	// --------------------------------------------

	char * minEnerTitle;

	// Graph Dimensions (for 600 x 400)
	float minEnerGraphWidth;
	float minEnerGraphHeight;

	// Current Graph Dimensions
	float currMinEnerGraphWidth;
	float currMinEnerGraphHeight;

	// Minimum Energy Position Variables
	float minEnerTitlePos[3];
	float minEnerGraphPos[3];

	// Graph Data
	vector<Point2fT> minEnerGraphPoints;
	
	float minEnerGraphXMin;
	float minEnerGraphYMin;

	float minEnerGraphYMax;
	float minEnerGraphXMax;

	// --------------------------------------------
	// RMSD
	// --------------------------------------------

	char * rmsdTitle;

	// Graph Dimensions (for 600 x 400)
	float rmsdGraphWidth;
	float rmsdGraphHeight;

	// Current Graph Dimensions
	float currRMSDGraphWidth;
	float currRMSDGraphHeight;

	// Minimum Energy Position Variables
	float rmsdTitlePos[3];
	float rmsdGraphPos[3];

	// Graph Data
	vector<Point2fT> rmsdGraphPoints;
	
	float rmsdGraphXMin;
	float rmsdGraphYMin;

	float rmsdGraphYMax;
	float rmsdGraphXMax;

	//last time the progress bar was updated
	time_t percentLastModified;
	time_t summaryLastModified;

	//for resolving names
	char resolved[RESOURCES_MAX_FILENAME];

	// --------------------------------------------
	// Constants
	// --------------------------------------------

	// Percent File Name
	static const char * PERCENT_FILE;
	static const char * SUMMARY_FILE;
	
	// Constant Placement Variables
	const float OBJECT_PADDING;
	const unsigned int MAX_GRAPH_POINTS;

};

#endif
